package com.lagou.dao;

import com.lagou.domain.AdminUser;
import com.lagou.utils.DruidUtils;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class AdminUserDao {
    /**
     * 检查用户名和密码
     * @param adminUser
     * @return
     */
    public static boolean checkLogin(AdminUser adminUser) {
        boolean flag = false;
        Connection con = null;
        PreparedStatement ps = null;
        ResultSet resultSet = null;
        try {
            con = DruidUtils.getConnection();

            String sql = "select * from admin_user where username = ? and password = ?";
            ps = con.prepareStatement(sql);

            ps.setString(1, adminUser.getUsername());
            ps.setString(2, adminUser.getPassword());

            resultSet = ps.executeQuery();

            if (resultSet.next()) {
                flag = true;
            }
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            DruidUtils.close(con, ps, resultSet);
        }

        return flag;
    }
}
